package cn.wolfcode.wolf2w.controller;

import cn.wolfcode.wolf2w.domain.Destination;
import cn.wolfcode.wolf2w.domain.StrategyCatalog;
import cn.wolfcode.wolf2w.query.StrategyCatalogQuery;
import cn.wolfcode.wolf2w.service.IDestinationService;
import cn.wolfcode.wolf2w.service.IStrategyCatalogService;
import cn.wolfcode.wolf2w.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Controller
@RequestMapping("strategyCatalog")
public class StrategyCatalogController {

    @Autowired
    private IStrategyCatalogService strategyCatalogService;

    @Autowired
    private IDestinationService destinationService;

    //页面数据和分页
    @RequestMapping("/list")
    public String List(Model model, @ModelAttribute("qo") StrategyCatalogQuery qo) {
        Page<StrategyCatalog> page = strategyCatalogService.query(qo);
        model.addAttribute("page", page);
        return "strategyCatalog/list";
    }


    //保存或修改
    @PostMapping("/saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(StrategyCatalog strategyCatalog){
        //设置关联目的地和保存修改操作
        strategyCatalogService.saveOrUpdate(strategyCatalog);
        return JsonResult.success();
    }


    //删除
    @GetMapping("/delete")
    @ResponseBody
    public Object delete(String id){
        strategyCatalogService.delete(id);
        return JsonResult.success();
    }
}
